package tests;

import board.Board;
import board.Piece;
import player.MachinePlayer;
import player.Move;

public class BoardTests {

	public static void main(String[] args){
		checkLegalMoves();
		checkStepMoves();
	}

	public static void checkLegalMoves(){
		Board b = new Board();
		boolean check;
		
		check = b.isLegal(new Move(-1,-1), Piece.BLACK);
		check("Out of board", false,check);
		check = b.isLegal(new Move(9,2), Piece.BLACK);
		check("Out of board", false,check);
		check = b.isLegal(new Move(0,0), Piece.BLACK);
		check("Out of bounds corner move ", false,check);
		check = b.isLegal(new Move(7,0), Piece.BLACK);
		check("Out of bounds corner move ", false,check);
		check = b.isLegal(new Move(0,7), Piece.BLACK);
		check("Out of bounds corner move ", false,check);
		check = b.isLegal(new Move(7,7), Piece.BLACK);
		check("Out of bounds corner move ", false,check);
		
		check = b.isLegal(new Move(0,1), Piece.BLACK);
		check("Out of bounds home row move", false,check);
		check = b.isLegal(new Move(7,4), Piece.BLACK);
		check("Out of bounds home row move", false,check);
		check = b.isLegal(new Move(1,0), Piece.WHITE);
		check("Out of bounds home row move", false,check);
		check = b.isLegal(new Move(6,7), Piece.WHITE);
		check("Out of bounds home row move", false,check);
		
		check = b.isLegal(new Move(1,1), Piece.BLACK);
		check("Performing a legal move ", true,check);
		b.makeMove(new Move(1,1), Piece.BLACK);
		check = b.isLegal(new Move(1,1), Piece.WHITE);
		check("Adding a piece on an occupied spot", false,check);
		check = b.isLegal(new Move(1,1), Piece.BLACK);
		check("Adding a piece on an occupied spot", false,check);
		
		check = b.isLegal(new Move(2,1), Piece.BLACK);
		check("Performing a legal move ", true,check);
		b.makeMove(new Move(2,1), Piece.BLACK);
		check = b.isLegal(new Move(3,1), Piece.BLACK);
		check("Adding a piece that would connect 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(3,2), Piece.BLACK);
		check("Adding a piece that would connect 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(2,2), Piece.BLACK);
		check("@Adding a piece that would connect 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(1,2), Piece.BLACK);
		check("@Adding a piece that would connect 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(1,0), Piece.BLACK);
		check("@Adding a piece that would connect 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(2,0), Piece.BLACK);
		check("@Adding a piece that would connect 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(2,2), Piece.WHITE);
		check("@Adding an opposite color piece to the 3 consecutive pieces", true,check);
	}
	
	public static void checkStepMoves(){
		Board b = new Board();
		boolean check;
		check = b.isLegal(new Move(2,2,1,1), Piece.BLACK);
		check("Trying to step a piece that does not exist", false,check);
		
		b.makeMove(new Move(1,1), Piece.BLACK);
		
		check = b.isLegal(new Move(2,2,1,1), Piece.BLACK);
		check("Trying step a piece", true,check);
		
		b.makeMove(new Move(2,2,1,1), Piece.BLACK);
		b.makeMove(new Move(1,1), Piece.BLACK);
		b.makeMove(new Move(6,6), Piece.BLACK);
		
		check = b.isLegal(new Move(3,3,6,6), Piece.BLACK);
		check("Trying step into 3 consecutive pieces", false,check);
		check = b.isLegal(new Move(1,2,2,2), Piece.BLACK);
		check("Trying a legal adjacent step", true,check);
	}
	
	static int count = 0;
	static void check(String test, Object expected, Object result){
		System.out.println(count+": " +test);
		System.out.flush();
		if( expected.equals(result)){
			System.out.println("\tpassed...");
			System.out.flush();
		}
		else{
			try{
				throw new RuntimeException(test+" failed");
			}
			catch(RuntimeException e){
				e.printStackTrace();
			}
		}
		count++;
	}
	
}
